package com.zzyl.task;

import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.zzyl.entity.Reservation;
import com.zzyl.mapper.ReservationMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;
@Slf4j
@Component
public class ReservationTask {
    @Autowired
    private ReservationMapper reservationMapper;

    @Scheduled(cron = "0 15,45 * * * ?")
    public void cancelReservation() {
        //将状态为0 ,time<当前时间的预约状态修改为3
        LambdaUpdateWrapper<Reservation> wrapper = new LambdaUpdateWrapper<>();
        wrapper.eq(Reservation::getStatus, 0)
                .le(Reservation::getTime, LocalDateTime.now()) ;
        Reservation reservation=new Reservation();
        reservation.setStatus(3);
        reservationMapper.update(reservation,wrapper);
        log.info("过期预约已取消");
    }
}
